slimecing

a fighting game featuring slimes and swords
Log | Files | Refs | README

TMP_Bitmap.shader (3466B)


      1 Shader "TextMeshPro/Bitmap" {
      2 
      3 Properties {
      4 	_MainTex		("Font Atlas", 2D) = "white" {}
      5 	_FaceTex		("Font Texture", 2D) = "white" {}
      6 	_FaceColor		("Text Color", Color) = (1,1,1,1)
      7 
      8 	_VertexOffsetX	("Vertex OffsetX", float) = 0
      9 	_VertexOffsetY	("Vertex OffsetY", float) = 0
     10 	_MaskSoftnessX	("Mask SoftnessX", float) = 0
     11 	_MaskSoftnessY	("Mask SoftnessY", float) = 0
     12 
     13 	_ClipRect("Clip Rect", vector) = (-32767, -32767, 32767, 32767)
     14 
     15 	_StencilComp("Stencil Comparison", Float) = 8
     16 	_Stencil("Stencil ID", Float) = 0
     17 	_StencilOp("Stencil Operation", Float) = 0
     18 	_StencilWriteMask("Stencil Write Mask", Float) = 255
     19 	_StencilReadMask("Stencil Read Mask", Float) = 255
     20 
     21 	_ColorMask("Color Mask", Float) = 15
     22 }
     23 
     24 SubShader{
     25 
     26 	Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
     27 	
     28 	Stencil
     29 	{
     30 		Ref[_Stencil]
     31 		Comp[_StencilComp]
     32 		Pass[_StencilOp]
     33 		ReadMask[_StencilReadMask]
     34 		WriteMask[_StencilWriteMask]
     35 	}
     36 	
     37 	
     38 	Lighting Off
     39 	Cull [_CullMode]
     40 	ZTest [unity_GUIZTestMode]
     41 	ZWrite Off
     42 	Fog { Mode Off }
     43 	Blend SrcAlpha OneMinusSrcAlpha
     44 	ColorMask[_ColorMask]
     45 
     46 	Pass {
     47 		CGPROGRAM
     48 		#pragma vertex vert
     49 		#pragma fragment frag
     50 
     51 		#pragma multi_compile __ UNITY_UI_CLIP_RECT
     52 		#pragma multi_compile __ UNITY_UI_ALPHACLIP
     53 
     54 
     55 		#include "UnityCG.cginc"
     56 
     57 		struct appdata_t {
     58 			float4 vertex		: POSITION;
     59 			fixed4 color		: COLOR;
     60 			float2 texcoord0	: TEXCOORD0;
     61 			float2 texcoord1	: TEXCOORD1;
     62 		};
     63 
     64 		struct v2f {
     65 			float4	vertex		: SV_POSITION;
     66 			fixed4	color		: COLOR;
     67 			float2	texcoord0	: TEXCOORD0;
     68 			float2	texcoord1	: TEXCOORD1;
     69 			float4	mask		: TEXCOORD2;
     70 		};
     71 
     72 		uniform	sampler2D 	_MainTex;
     73 		uniform	sampler2D 	_FaceTex;
     74 		uniform float4		_FaceTex_ST;
     75 		uniform	fixed4		_FaceColor;
     76 
     77 		uniform float		_VertexOffsetX;
     78 		uniform float		_VertexOffsetY;
     79 		uniform float4		_ClipRect;
     80 		uniform float		_MaskSoftnessX;
     81 		uniform float		_MaskSoftnessY;
     82 
     83 		float2 UnpackUV(float uv)
     84 		{
     85 			float2 output;
     86 			output.x = floor(uv / 4096);
     87 			output.y = uv - 4096 * output.x;
     88 
     89 			return output * 0.001953125;
     90 		}
     91 
     92 		v2f vert (appdata_t v)
     93 		{
     94 			float4 vert = v.vertex;
     95 			vert.x += _VertexOffsetX;
     96 			vert.y += _VertexOffsetY;
     97 
     98 			vert.xy += (vert.w * 0.5) / _ScreenParams.xy;
     99 
    100 			float4 vPosition = UnityPixelSnap(UnityObjectToClipPos(vert));
    101 
    102 			fixed4 faceColor = v.color;
    103 			faceColor *= _FaceColor;
    104 
    105 			v2f OUT;
    106 			OUT.vertex = vPosition;
    107 			OUT.color = faceColor;
    108 			OUT.texcoord0 = v.texcoord0;
    109 			OUT.texcoord1 = TRANSFORM_TEX(UnpackUV(v.texcoord1), _FaceTex);
    110 			float2 pixelSize = vPosition.w;
    111 			pixelSize /= abs(float2(_ScreenParams.x * UNITY_MATRIX_P[0][0], _ScreenParams.y * UNITY_MATRIX_P[1][1]));
    112 
    113 			// Clamp _ClipRect to 16bit.
    114 			float4 clampedRect = clamp(_ClipRect, -2e10, 2e10);
    115 			OUT.mask = float4(vert.xy * 2 - clampedRect.xy - clampedRect.zw, 0.25 / (0.25 * half2(_MaskSoftnessX, _MaskSoftnessY) + pixelSize.xy));
    116 			
    117 			return OUT;
    118 		}
    119 
    120 		fixed4 frag (v2f IN) : SV_Target
    121 		{
    122 			fixed4 color = tex2D(_MainTex, IN.texcoord0);
    123 			color = fixed4 (tex2D(_FaceTex, IN.texcoord1).rgb * IN.color.rgb, IN.color.a * color.a);
    124 
    125 			// Alternative implementation to UnityGet2DClipping with support for softness.
    126 			#if UNITY_UI_CLIP_RECT
    127 				half2 m = saturate((_ClipRect.zw - _ClipRect.xy - abs(IN.mask.xy)) * IN.mask.zw);
    128 				color *= m.x * m.y;
    129 			#endif
    130 
    131 			#if UNITY_UI_ALPHACLIP
    132 				clip(color.a - 0.001);
    133 			#endif
    134 
    135 			return color;
    136 		}
    137 		ENDCG
    138 	}
    139 }
    140 
    141 	CustomEditor "TMPro.EditorUtilities.TMP_BitmapShaderGUI"
    142 }